package com.immediatus.engine.util;

import com.immediatus.engine.contracts.IUnit;
import com.immediatus.util.InsertionSorter;

import java.util.Comparator;
import java.util.List;


public class ZIndexSorter extends InsertionSorter<IUnit>{
    private static ZIndexSorter INSTANCE;

    private final Comparator<IUnit> _ZIndexComparator = new Comparator<IUnit>(){
        @Override
        public int compare(final IUnit unitA_, final IUnit unitB_){
            return unitA_.getZIndex() - unitB_.getZIndex();
        }
    };

    private ZIndexSorter(){
    }

    public static ZIndexSorter getInstance(){
        if (INSTANCE == null){
            INSTANCE = new ZIndexSorter();
        }
        return INSTANCE;
    }

    public void sort(final IUnit[] units_){
        this.sort(units_, this._ZIndexComparator);
    }

    public void sort(final IUnit[] units_, final int start_, final int end_){
        this.sort(units_, start_, end_, this._ZIndexComparator);
    }

    public void sort(final List<IUnit> units_){
        this.sort(units_, this._ZIndexComparator);
    }

    public void sort(final List<IUnit> units_, final int start_, final int end_){
        this.sort(units_, start_, end_, this._ZIndexComparator);
    }
}